﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		/* 回执信息 */
		response = structNew();
		structInsert(response, "success", false, true);
		
		/* 老系统成绩编号 */
		boookedcourseId = event.getArg("bookedcourseId");
		
		transaction {
			
			sql = "SELECT count(*) count from t_student_mark a, t_student_mark b 
					WHERE b.bookedcourse_id = :bookedcourseid 
					AND a.stu_id = b.stu_id AND a.cid = b.cid ";
			
			queryObj = new query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="bookedcourseid", value=bookedcourseid, cfsqltype="cf_sql_varchar" );
			
			rs_studentMark = queryObj.execute( sql=sql ).getResult();	
			
			if( rs_studentMark.count gt '1'){
					
				sql = "INSERT INTO t_student_mark_repeat 
		  select  * from t_student_mark a where a.bookedcourse_id = :bookedcourseid ";
				
				queryObj = new query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="bookedcourseid", value=bookedcourseid, cfsqltype="cf_sql_varchar" );
				
				queryObj.execute( sql=sql );
				
				sql = "DELETE FROM t_student_mark WHERE bookedcourse_id = :bookedcourseid ";
				
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="bookedcourseid", value=bookedcourseid, cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
	
				structInsert(response, "success", true, true);
			}else{
				structInsert(response, "success", false, true);
				structInsert(response, "reason", "该学生这个课程已经没有重复成绩", true);
			}

		}

	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>